from django.shortcuts import render

# Create your views here.

from guide.models import GuideDirection, GuideClassification, GuideDescription, GuideContent
from guide.ser import GuideDirectionSerializer, GuideClassificationSerializer, GuideDescriptionSerializer, GuideContentSerializer

from rest_framework.generics import ListAPIView
from rest_framework.pagination import PageNumberPagination
from rest_framework.filters import OrderingFilter

# 分页配置
class StandardResultsSetPagination(PageNumberPagination):
    page_size = 10
    page_size_query_param = 'page_size'
    max_page_size = 100

# 排序配置
class CustomOrderingFilter(OrderingFilter):
    ordering_params = ('name', 'time')


# 急救指南 ListAPIView
class FirstaidGuideListView(ListAPIView):
    serializer_class = GuideDirectionSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name']

    def get_queryset(self):
        return GuideDirection.objects.all()

# 急救指南 ListAPIView
class FirstaidGuideListView(ListAPIView):
    serializer_class = GuideClassificationSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name']

    def get_queryset(self):
        return GuideClassification.objects.all()

# 急救类别 ListAPIView
class GuideDescriptionListView(ListAPIView):
    serializer_class = GuideDescriptionSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['name']

    def get_queryset(self):
        return GuideDescription.objects.all()

# 急救信息 ListAPIView
class GuideContentListView(ListAPIView):
    serializer_class = GuideContentSerializer
    pagination_class = StandardResultsSetPagination
    filter_backends = [CustomOrderingFilter]
    ordering_fields = ['time', 'title']

    def get_queryset(self):
        return GuideContent.objects.all()